home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-06-03 | 1.9 KB | 87 lines | [TEXT/MPS ] |
- /*************************************************************************************
- *
- * Apply a ShellSort algorithm to an offscreen, scrambled GWorld
- *
- * ShellSort.cp - C Source
- *
- * Copyright © Apple Computer, Inc. 1988 - 1993
- * All rights reserved.
- *
- * This is the "guts" of the SortPicts program. This file performs the actual
- * sort algorithm which gives the image its restoration quality (restoring itself
- * to its original self).
- *
- *************************************************************************************/
- #include "GWorldObj.h"
-
-
-
- /*************************************************************/
- /* */
- /* The Actual Sort Algorithms */
- /* */
- /*************************************************************/
-
-
- void GWorldObj :: ShellSort( void)
- {
- long loop, sortSize, inLoop;
- long min;
- long data;
- long *tickPtr = (long *)0x16A;
- char mmuMode = true32b;
-
- SetTitle( (const unsigned char*)"\pShell Sorting");
-
- SwapMMUMode( &mmuMode);
- UseGWorld();
-
- HLock( (Handle)sortList);
- sortListPtr = *sortList;
- if( !sortListPtr)
- return;
-
- sortSize = 1;
- while( sortSize < N)
- sortSize = 3 * sortSize + 1;
-
- do
- {
- sortSize /= 3;
- for( loop = sortSize; loop < N; ++loop)
- {
-
- min = sortListPtr[loop];
-
- inLoop = loop;
- while( (data = sortListPtr[inLoop - sortSize]) > min)
- {
- SetSortItem( inLoop, data);
-
- inLoop -= sortSize;
- if( inLoop < sortSize)
- goto Next;
- else
- if( YieldIfTime( &mmuMode))
- goto SortErrQuit;
- }
- Next:
- SetSortItem( inLoop, min);
- }
- } while( sortSize > (gSortSize * 4)); // 1 = cool picts; 0 = actual sort
-
- UnuseGWorld();
- SwapMMUMode( &mmuMode);
-
- SortErrQuit:
- HUnlock( (Handle)sortList);
- SetTitle( (const unsigned char*)"\pDone");
-
- doneSorting = true;
- finishedTime = TickCount();
- DrawObj();
- }
-
-
-
-